package com.hhh.springai_test.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hhh.springai_test.common.ErrorCode;
import com.hhh.springai_test.exception.BusinessException;
import com.hhh.springai_test.model.po.Banner;
import com.hhh.springai_test.service.BannerService;
import com.hhh.springai_test.mapper.BannerMapper;
import com.hhh.springai_test.model.dto.AddBannerDTO;
import com.hhh.springai_test.model.dto.UpdateBannerDTO;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

/**
* @author 29915
* @description 针对表【banner】的数据库操作Service实现
* @createDate 2025-02-01 10:56:28
*/
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner>
    implements BannerService {

    @Override
    public Boolean addBanner(AddBannerDTO addBannerDTO) {
        Banner banner = new Banner();
        banner.setBannerurl(addBannerDTO.getBannerurl());
        banner.setBannertitle(addBannerDTO.getBannertitle());
        banner.setCreatetime(new Date());
        banner.setUpdatetime(new Date());
        return save(banner);
    }

    @Override
    public Boolean updateBanner(UpdateBannerDTO updateBannerDTO) {
        Banner banner = getById(updateBannerDTO.getId());
        if (banner == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"这个banner不存在");
        }
        banner.setBannerurl(updateBannerDTO.getBannerurl());
        banner.setBannertitle(updateBannerDTO.getBannertitle());
        banner.setUpdatetime(new Date());
        return updateById(banner);
    }

    @Override
    public Boolean deleteBanner(Long id) {
        Banner banner = getById(id);
        if (banner == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"这个banner不存在");
        }
        return removeById(id);
    }

    @Override
    public List<Banner> listBanner() {
        return list();
    }
}




